<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Goods extends Model
{
    use SoftDeletes;
	//指定表名
	protected $table='goods';
	//指定id
	protected $primaryKey ='id';
    // 日期都存储为时间戳
    protected $dateFormat = 'U';

    // 将价格改变面额单位从元换算成分
    public function setPriceAttribute($value)
    {
        $this->attributes['price'] = $value*100;
    }
    // 将价格改变面额单位从分换算成元
    public function getPriceAttribute($value)
    {
        return $value/100;
    }

    public function product()
    {
        return $this->belongsTo('App\Product', 'product_id', 'id');
    }
}
